/*******************************************************************************
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package org.desktop.web.server.util;

import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.lang3.RandomStringUtils;
import org.desktop.web.client.util.UtilService;

import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class UtilServiceImpl extends RemoteServiceServlet implements
		UtilService {

	@Override
	public String jobTime(DayTime dayTime, TypeHour type) {
		System.out.println("UtilServiceImpl.jobTime()");
		try {
			GregorianCalendar gc = (GregorianCalendar) GregorianCalendar
					.getInstance();
			int hour = (type.equals(TypeHour.START_HOUR) ? (dayTime
					.equals(DayTime.BEFORE_LUNCH) ? 9 : 14) : (dayTime
					.equals(DayTime.BEFORE_LUNCH) ? 13 : 18));
			int minute = 0;
			gc.set(Calendar.HOUR_OF_DAY, hour);
			gc.set(Calendar.MINUTE, minute);
			SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat
					.getTimeInstance(SimpleDateFormat.FULL);
			sdf.applyPattern("HH:mm");
			// TODO Auto-generated method stub
			return sdf.format(gc.getTime());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

	@Override
	public String randomAlphaNumeric(int size) {
		// TODO Auto-generated method stub
		return RandomStringUtils.randomAlphanumeric(size);
	}

	@Override
	public int randomNumeric(int size) {
		// TODO Auto-generated method stub
		return Integer.parseInt(RandomStringUtils.randomNumeric(size));
	}

	@Override
	public String randomString(int size) {
		// TODO Auto-generated method stub
		return RandomStringUtils.randomAlphabetic(size);
	}

}
